local skill = fk.CreateSkill{
  name = "action__tangying_skill",
}

Fk:loadTranslationTable{
  ["action__tangying"] = "躺赢",
  ["action__tangying_skill"] = "躺赢",
  [":action__tangying"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：你 <br /><b>效果</b>：选择一名其他角色并结束当前回合且你翻面，令其的下回合开始时其选择执行一个额外的摸牌或出牌阶段。（不可响应）",
  ["#action__tangying_skill"] = "选择一名其他角色并结束当前回合且你翻面，令其的下回合开始时其选择执行一个额外的摸牌或出牌阶段",
  ["@@action__tangying1"] = "躺赢",
  ["@action__tangying2"] = "带飞",
  ["#action__tangying_draw"] = "摸牌阶段",
  ["#action__tangying_play"] = "出牌阶段",
}


skill:addEffect("cardskill", {
  mute = true,
  name = "action__tangying",
  prompt = "#action__tangying_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    cardUseEvent.disresponsiveList = table.simpleClone(Fk:currentRoom().players)
    if not cardUseEvent.tos or #cardUseEvent.tos == 0 then
      cardUseEvent.tos = { cardUseEvent.from }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:askToChoosePlayers(effect.to, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(effect.to),
      skill_name = self.name,
      cancelable = false,
      prompt = "#action__tangying_skill",
    })
    if #to > 0 then
      room:addPlayerMark(effect.to, "@@action__tangying1")
      room:setPlayerMark(to[1], "@action__tangying2", Fk:translate(effect.to.general))
    end
    effect.to:turnOver()
    room.logic:breakTurn()
  end,
})


skill:addEffect(fk.TurnStart, {
  mute = true,
  global = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@action__tangying2") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = { "#action__tangying_draw", "#action__tangying_play" },
      skill_name = self.name,
      cancelable = true,
      prompt = "请选择额外执行的阶段",
    })
    room:setPlayerMark(player, "@action__tangying2", 0)
    for _, p in ipairs(room.alive_players) do
      if p:getMark("@@action__tangying1") > 0 then
        room:setPlayerMark(p, "@@action__tangying1", 0)
      end
    end
    if choice == "#action__tangying_draw" then
      player:gainAnExtraPhase(Player.Draw,self.name,false)
    else
      player:gainAnExtraPhase(Player.Play,self.name,false)
    end
  end,
})


return skill